let $axios = require('axios')
$axios.defaults.baseURL = 'http://localhost:8090/api'

/***************员工*******************/
export  function  loadEmployees(){
  return new Promise((resolve, reject) => {
    $axios.get('/setting/employee/all').then(resp=>{
      if(resp && resp.status==200){
        let data = resp.data;
        console.log(JSON.stringify(data));
        resolve(data);
      }
    })
  })
}
export function loadEmployeesBySenior(senior){
  return new Promise((resolve, reject) => {
    $axios.get(`/setting/employee/senior?senior=${senior}`).then(resp=>{
      if(resp&&resp.status==200){
        resolve(resp.data)
      }
      reject(resp);
    })
  })
}
export function delEmployee(_account){
  return new Promise((resolve, reject) => {
    $axios.post(`setting/employee/del?account=${_account}`).then(
      resp=>{
        if(resp&&resp.status==200){
          resolve(200);
        }
      }
    )
  })
}

/**
 * @Description:添加新员工
 * @Param:
 * @return:
 * @Author: anqing.lisng
 * @Date: 2021/3/24
 */
export function addNewEmployee(staff){
  //staff.Pcash=true;
  return staff?new Promise((resolve, reject) => {
    $axios.post('/setting/employee/add',staff).then((resp)=>{
      if(resp && resp.status==200){
        console.log((resp.data.code==200));
        resp.data.code==200?resolve(resp.data):reject(resp.data);
      }
    })
  }):null
}
/***
* @Description: 员工更新
* @Param:
* @return:
* @Author: anqing.liang
* @Date: 2021/4/20
*/
export  function $updateEmployee(staff){
  return staff?new Promise((resolve, reject) => {
    $axios.post('/setting/employee/update',staff).then(resp=>{
      if(resp && resp.status==200){
        resolve(resp.data);
      }
      reject(resp);
    })
  }):null
}
/***
* @Description: 模糊查询
* @Param:
* @return:
* @Author: anqing.liang
* @Date: 2021/5/18
*/
export function $findByQuery(query){
  return new Promise((resolve, reject) => {
    $axios.get(`/setting/employee/query?query=${query}`).then(resp=>{
      if(resp && resp.status==200){
        resolve(resp)
      }
      reject(resp);
    })
  })
}
/******************类别*********************/
export function loadKinds(){
  return new Promise((resolve, reject) => {
    $axios.get('/kinds').then(resp => {
      if (resp && resp.status === 200) {
        resolve(resp.data)
      }
      reject(resp);
    })
  })
}
export function $addKind(_kind){
  return new Promise((resolve, reject) => {
    $axios.post('/kinds/add', {
        kind:_kind
      }).then(resp => {
      if (resp && resp.status === 200) {
        //this.dialogFormVisible = false
        let rs=resp.data
        rs.code==200?resolve(rs.data):reject(rs);
      }
    })
  })
}
